package com.zjxf.service.impl;

import com.zjxf.base.bean.po.LHNTTravelPlan;
import com.zjxf.base.common.SysConst;
import com.zjxf.repository.LHNTTravelPlanRepository;
import com.zjxf.service.LHNTTravelPlanService;
import lombok.AllArgsConstructor;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.Predicate;
import javax.transaction.Transactional;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 我要出征
 *
 * @author lihaonan
 * @date 2021/4/6/006 19:11
 */
@AllArgsConstructor
@Service
@Transactional(rollbackOn = RuntimeException.class)
public class LHNTTravelPlaneServiceImpl implements LHNTTravelPlanService {

    private final LHNTTravelPlanRepository lhntTravelPlanRepository;

    /**
     *
     * 保存用户信息
     * @param lhntTravelPlan
     * @return
     */
    @Override
    public LHNTTravelPlan addTravelPlan(LHNTTravelPlan lhntTravelPlan) {
        return lhntTravelPlanRepository.save(lhntTravelPlan);
    }

    /**
     *
     * 查询路线id
     * @return
     */
    @Override
    public List<Long> findAll() {
        Specification<LHNTTravelPlan> specification= (Specification<LHNTTravelPlan>) (root, criteriaQuery, criteriaBuilder) -> {
            Predicate pre = criteriaBuilder.equal(root.get("deleteState"), SysConst.DeleteState.UN_DELETE_STATE.getCode());
            return pre;
        };
        List<LHNTTravelPlan> list = lhntTravelPlanRepository.findAll(specification);
        List<Long> idList = list.stream().map(LHNTTravelPlan::getRouteId).collect(Collectors.toList());
        return idList;
    }
}
